﻿
Imports SponsorshipLogic
Imports SponsorshipLogic.User
Imports SponsorshipLogic.Activity

Public Class frmChild

    Private _Child As SponsorshipLogic.Child

    Public Property Id As Integer
        Get
            Id = _Child.Id
        End Get
        Set(ByVal value As Integer)
            CurrentUser.Activity.AddRecentActivity(ActivityType.atChild, value)
            _Child = Child.Load(value)
            CtlChild1.ChildName = _Child.Name
            CtlChild1.DateOfBirth = _Child.DateOfBirth
            CtlChild1.Gender = _Child.Gender
            CtlChild1.State = _Child.State
            CtlNotes1.Notes = _Child.Notes
        End Set
    End Property



    Private Sub optEdit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optEdit.CheckedChanged
        CtlChild1.Editable = True
    End Sub

    Private Sub optView_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optView.CheckedChanged
        CtlChild1.Editable = False
    End Sub

    Private Sub CtlChild1_Changed() Handles CtlChild1.Changed
        btnSave.Enabled = True
    End Sub

    Private Sub CtlChild1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CtlChild1.Load

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        SaveChild()
    End Sub

    Private Sub SaveChild()
        Throw New NotImplementedException
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub CtlNotes1_DeleteNote(ByRef oNote As SponsorshipLogic.Note, ByRef Cancel As Boolean) Handles CtlNotes1.DeleteNote
        Try
            oNote.delete()
            CtlNotes1.Notes = _Child.Notes

        Catch ex As Exception
            Cancel = True
        End Try

    End Sub



    Private Sub CtlNotes1_SaveNote(ByRef oNote As SponsorshipLogic.Note) Handles CtlNotes1.SaveNote

        Try
            If oNote.Id = 0 Then
                oNote.Save()
                _Child.AddNote(oNote)
            Else
                oNote.Save()
            End If
            CtlNotes1.Notes = _Child.Notes

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

    Private Sub CtlNotes1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CtlNotes1.Load

    End Sub
End Class